<template>
	<view class="cu-modal margin-top-sm" :class="showModel?'show':''">
		<view class="cu-dialog">
			
			<!-- 标题 begin -->
			<view class="cu-bar bg-white justify-end">
				<view class="content">用户信息</view>
				<view class="action" @tap="closeWin">
					<text class="cuIcon-close text-red"></text>
				</view>
			</view>
			<!-- 标题 end -->
			
			<!-- 详情 begin -->	
			<view>
				
				<!-- 头像部分 begin -->
				<view class="cu-list menu-avatar">
					<view class="cu-item">			
						<view class="cu-avatar round lg" :style="'background-image:url('+userinfo.avatar+');'"></view>								
						<view class="content">						
							<view class="text-black">										
								{{userinfo.name}}
							</view>
							<view class="text-gray text-sm flex">
								<view class="text-cut">											
									<text class="text-cyan" v-if="userinfo.isAuth">微信用户</text>
									<text class="text-gray" v-else>未认证</text>											
									<text class="text-orange margin-left-xs" v-if="userinfo.hasIdCard">已传证件</text>
									<text class="text-gray margin-left-xs" v-else>未传证件</text>											
									<text class="text-gray margin-left-xs" v-if="userinfo.schoolId!=null&&!userinfo.isCheck">信息待检</text>
									<text class="text-green margin-left-xs" v-if="userinfo.isCheck">信息已检</text>											
								</view>
							</view>
						</view>
					</view>
				</view>
				<!-- 头像部分 end -->
				
				<!-- 信息 begin -->
				<view class="cu-list menu sm-border margin-0-top-i text-left">
					<view class="cu-item">
						<view class="content"><text class="cuIcon-location text-green"></text><text class="text-grey">所在位置</text></view>
						<view class="action">
							<text class="text-grey text-sm" v-if="userinfo.province==null||userinfo.province==0">未设置</text>
							<text class="text-grey text-sm" v-else>{{userinfo.province}} {{userinfo.city}} {{userinfo.area}}</text>
						</view>
					</view>							
					<view class="cu-item">
						<view class="content"><text class="cuIcon-peoplelist text-yellow"></text><text class="text-grey">学校</text></view>
						<view class="action">
							<text class="text-grey text-sm" v-if="userinfo.school==null">未设置</text>
							<text class="text-grey text-sm" v-else>{{userinfo.school}}</text>
						</view>
					</view>
					<view class="cu-item">
						<view class="content"><text class="cuIcon-discover text-orange"></text><text class="text-grey">院系</text></view>
						<view class="action">
							<text class="text-grey text-sm" v-if="userinfo.department==null">未设置</text>
							<text class="text-grey text-sm" v-else>{{userinfo.academy}} {{userinfo.department}}</text>
						</view>
					</view>
					<view class="cu-item">
						<view class="content"><text class="cuIcon-addressbook text-pink"></text><text class="text-grey">班级</text></view>						
						<view class="action">
							<text class="text-grey text-sm" v-if="userinfo.classes==null">未设置</text>
							<text class="text-grey text-sm" v-else>{{userinfo.major}} {{userinfo.classes}}</text>
						</view>
					</view>
					<view class="cu-item">
						<view class="content"><text class="cuIcon-vipcard text-red"></text><text class="text-grey">学生证</text></view>
						<view class="action padding-top-xs">
							<text class="text-green text-sm" v-if="userinfo.hasIdCard">已上传</text>
							<text class="text-grey text-sm" v-else>未上传</text>														
						</view>
					</view>
				</view>
				<!-- 信息 end -->
				
				<view class="cu-bar bg-white flex justify-center">
					<button class="cu-btn bg-red radius" style="width: 95%;" @tap="closeWin">关闭</button>
				</view>
				
			</view>
			<!-- 详情 end -->
				
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo:{
					name:'微信用户',
					avatar:'',
					
					province:'未设置',
					city:'未设置',
					area:'未设置',
					school:'未设置',
					
					department:'未设置',
					academy:'未设置',
					department:'未设置',
					major:'未设置',
					classes:'未设置',
					idCard:null,
				},
			};
		},
		name: 'user-detail-win',
		props: {
			userId: {
				type: Number,
				default: -1
			},
			showModel: {
				type: [Boolean, String],
				default: false
			},
		},
		created() {
			this.loadUser(this.userId)
		},
		watch:{
			userId(userId){
				this.loadUser(userId)
			}
		},
		methods: {
			closeWin(){
				this.$emit("closeWin")
			},
			loadUser(userId){
				if(userId>0){
					this.$api.post('/user/detail',{userId:userId}).then(res => {
						if (res.code == 200){
							this.userinfo=res.data
						}else{
							console.log(res.msg)
							uni.showToast({
								icon: 'none',
								title: '网络异常'
							})
						}
						
					}).catch(error=>{
						console.log(error)
						uni.showToast({
							icon: 'none',
							title: '网络异常'
						})
					})
				}
			}
		}
	}
</script>

<style>
</style>